import {v4 as uuidv4} from 'uuid';
import { jsonp } from 'vue-jsonp'
import sha256 from "sha256";


export const translateKeyword = (keyword, from, to) => {
  const youdao = 'https://openapi.youdao.com/api'
  const appKey = '0338858e40915a85'
  const app_sign = 'LtUyIqGP9NfYNBu5O6fasrFhcl6sSZIy'
  const salt = uuidv4() + ''
  const curtime = Math.round(new Date().getTime() / 1000) + '';
  const sign = sha256(appKey + keyword + salt + curtime + app_sign)

  const data = {
    q: keyword,
    appKey: appKey,
    salt: salt,
    from: from,
    to: to,
    sign: sign,
    signType: "v3",
    curtime: curtime,
  }

  return jsonp(youdao, data)

}
